package com.ctvit.cch.core.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ctvit.cch.core.mapper.HotRecordFavoriteMapper;
import com.ctvit.cch.core.pojo.domain.HotRecordFavorite;
import com.ctvit.cch.core.pojo.dto.hot.HotRecordFavoriteAddDTO;
import com.ctvit.cch.core.pojo.dto.hot.HotRecordFavoriteBatchAddDTO;
import com.ctvit.cch.core.service.IHotRecordFavoriteService;
import com.ruoyi.common.utils.SecurityUtils;
import java.util.List;
import java.util.stream.Collectors;

import org.springframework.stereotype.Service;

/**
 * 热点数据收藏Service业务层处理
 *
 * @author heyingcheng
 * @date 2025/11/07
 */
@Service
public class HotRecordFavoriteServiceImpl extends ServiceImpl<HotRecordFavoriteMapper, HotRecordFavorite>
        implements IHotRecordFavoriteService {

    @Override
    public boolean add(HotRecordFavoriteAddDTO dto) {
        HotRecordFavorite entity = new HotRecordFavorite();
        entity.setRecordId(dto.getRecordId());
        entity.setUserId(SecurityUtils.getUserId());

        return save(entity);
    }

    @Override
    public boolean batchAdd(HotRecordFavoriteBatchAddDTO dto) {
        Long userId = SecurityUtils.getUserId();
        // 将批量的记录ID转换为收藏实体列表
        List<HotRecordFavorite> entities = dto.getRecordIds().stream()
                .map(recordId -> {
                    HotRecordFavorite entity = new HotRecordFavorite();
                    entity.setRecordId(recordId);
                    entity.setUserId(userId);
                    return entity;
                })
                .collect(Collectors.toList());

        // 批量保存
        return saveBatch(entities);
    }

}